import * as THREE from 'three';
// 清理对象（不管用，只有 renderer.dispose() + forceContextLoss() 管用）
function disposeObject2(object: THREE.Object3D) {
  // 网格体
  if (object instanceof THREE.Mesh) {
    // 材质
    const material = object.material; // 纹理
    Object.keys(material).forEach((key) => {
      const texture = material[key];
      if (texture instanceof THREE.Texture) {
        texture.dispose(); // 贴图 dispose
        material[key] = undefined;
      }
    });
    material.dispose?.(); // 材质 dispose
    object.material = undefined; // 几何体
    const geometry = object.geometry;
    geometry.dispose(); // 几何体 dispose
    object.geometry = undefined;
  } // 递归
  object.children.forEach(disposeObject); // 解除树（不能要，会打乱树结构，进而使树的清理不完整） // if (object.parent) object.removeFromParent()
}

function disposeObject(object: THREE.Object3D) {}

export default disposeObject;
